package taller2.controller.modes;

import java.awt.event.MouseEvent;

import taller2.interfaces.Graph;
import taller2.utils.Point;
import taller2.view.draws.DrawingArea;
import taller2.view.draws.GraphDrawer;

public class DeleteNodeMode implements Mode {
	private Graph graph;
	
	// constructor
	public DeleteNodeMode(Graph graph){
		this.graph = graph;
	}
	
	// deletes the node when pressed with the mouse
	public void whenPressed(MouseEvent arg0, DrawingArea area) {
		GraphDrawer drawer = area.getDrawer();
		drawer.unselectNode();
		
		if(drawer.selectCloseByNode(new Point(arg0.getX(),arg0.getY()))){
			graph.deleteNode(drawer.getSelectedNodeIndex());
			drawer.unselectNode();
			area.repaint();
		}
	}

	public void whenReleased(MouseEvent arg0, DrawingArea area) {}

	public void whenDragged(MouseEvent arg0, DrawingArea area) {}

}
